//
//  BaseButton.m
//  YiCuiMiaoZhang
//
//  Created by Sings on 2019/5/29.
//  Copyright © 2018 益萃网络科技（中国）有限公司. All rights reserved.
//

#import "BaseButton.h"
#import "UIButton+BZ.h"

@implementation BaseButton

- (instancetype) initWithViewModel:(BaseButtonModel *) viewModel {
    
    self = [[self class] buttonWithType:UIButtonTypeCustom];
    [self initView];
    self.viewModel = viewModel;
    return self;
}

- (void) initView {
    
}


- (void)setViewModel:(BaseButtonModel *)viewModel {
    if (_viewModel) {
        _viewModel.refresh = nil;
        _viewModel.touchUpInside = nil;
    }
    _viewModel = viewModel;
    BaseWeakObj(self)
    _viewModel.refresh = ^{
        [weakself refreshView];
        
    };
    self.click = ^{
        if (weakself.viewModel.touchUpInside) {
            weakself.viewModel.touchUpInside();
        }
    };
    [self showView];
}


- (void)showView {
    if (self.viewModel.hide) {
        self.alpha = 0.;
    } else {
        self.alpha = 1.;
    }
}

- (void)refreshView {
    [self showView];
}


@end
